<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<strong><%@ taglib prefix="c"
                   uri="http://java.sun.com/jsp/jstl/core" %></strong>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>首页轮播</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/xAdmin/css/font.css">
    <link rel="stylesheet" href="/xAdmin/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/xAdmin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/xAdmin/js/xadmin.js"></script>

    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页轮播</a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name" id="name" placeholder="用户名" autocomplete="off" class="layui-input">
                        </div>
                        <button class="layui-btn" data-type="reload" id="demoTable">搜索</button>
                </div>

                <div class="layui-card-body ">
                    <div class="layui-card-header">
                        <button class="layui-btn" onclick="openL()"><i class="layui-icon"></i>添加</button>
                    </div>
                    <table class="layui-table" id="idTest" lay-filter="idTest" ></table>
                    <script type="text/html" id="barDemo">
<%--                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>--%>
                        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
                <div class="layui-card-body ">
                    <div class="page" id="page">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    var userid =null;
    var userdesc=null
    layui.use('table', function(){
        var table = layui.table;
        //第一个实例
        table.render({
            elem: '#idTest'
            ,url: '/tBizCarouse/getcaList' //数据接口
            ,cols: [[ //表头
                ,{field: 'id', title: 'ID', width:180}
                ,{field: 'name', title: '姓名', width:200}
                // ,{field: 'mainpic', title: '图片', width:150,
                // templet:function(d){
                //     console.log(d.mainpic);
                //     // return'<div> <img src="../photoshow.jsp?path='+d.mainpic+'"  /> </div>';
                //     return '<div> <img src="'+'../ajaxData/photoshow?imgPath='+d.mainpic+'&type=style/ys320"  /> </div>';
                //     }}
                ,{field: 'creater', title: '创建者', width:220 }
                ,{field: 'creatTime', title: '创建时间', width:200}
                ,{field: 'cStateDesc', title: '状态', width: 200}
                ,{field: 'soft', title: '排序', width: 200}
                ,{fixed: 'right', title:'操作',align:'center', toolbar: '#barDemo'}
            ]]
            ,id: 'testReload'
            ,page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout:  ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'] //自定义分页布局
                ,curr: 1 //设定初始在第 5 页
                ,groups: 3 //只显示 1 个连续页码
            }
            ,parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
        });

        var $ = layui.$, active = {
            reload: function(){
                var name = $('#name').val();
                var mobilephono = $('#mobilephono').val();

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                            name: name,
                            mobilephono:mobilephono
                    }
                }, 'data');
            }
        };

        $('#demoTable').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听行工具事件
        table.on('tool(idTest)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(layEvent === 'detail'){

            } else if(layEvent === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构
                    layer.close(index);
                    //向服务端发送删除指令
                });
            } else if(layEvent === 'edit'){
                layui.use('layer', function(){
                    var layer = parent.layui.layer;
                    var index = layer.open({
                        title: "编辑",
                        type: 2,
                        area: ["900px","700px"],
                        content: '/tBizCarouse/init?id='+data.id
                    });
                });
            }
        });



    });

    function openL(){
        console.log("ssssss");
        layui.use('layer', function(){
            var layer = parent.layui.layer;
            var index = layer.open({
                title: '新增',
                type: 2,
                area: ["900px","700px"],
                content: '/tBizCarouse/init',
                end: function () {
                    console.log("回调成功");
                    refreshTable();
                }
            });
        });
    }

    function refreshTable(){
        window.location.reload();
    }


</script>
</html>
